//
//  LWStatusToolBar.swift
//  Swift_Weibo_HLW
//
//  Created by huanglinwang on 16/9/23.
//  Copyright © 2016年 Linwang. All rights reserved.
//

import UIKit
// 微博首页底部toolBar视图
class LWStatusToolBar: UIView {
    
    
    
    
    //使用viewModel绑定数据
    var statusViewModel: LWStatusViewModel?{
        didSet{
            
            retweetBtn.setTitle(statusViewModel?.retweetCountContent, for: .normal)
            commentBtn.setTitle(statusViewModel?.commentCountContent, for: .normal)
            unlikeBtn.setTitle(statusViewModel?.unlikeCountContent, for: .normal)
            
        }
    }
    //懒加载 ->
    private lazy var retweetBtn: UIButton = self.addChildButton(imageName: "timeline_icon_retweet", title: "转发")
    private lazy var commentBtn: UIButton = self.addChildButton(imageName: "timeline_icon_comment", title: "评论")
    private lazy var unlikeBtn: UIButton = self.addChildButton(imageName: "timeline_icon_unlike", title: "赞")
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //添加控件设置约束
    private func setupUI() {
        

        
        //设置约束
        retweetBtn.snp_makeConstraints { (make) in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentBtn)
        }
        
        commentBtn.snp_makeConstraints { (make) in
            make.leading.equalTo(retweetBtn.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(unlikeBtn)
        }
        
        unlikeBtn.snp_makeConstraints { (make) in
            make.leading.equalTo(commentBtn.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.trailing.equalTo(self)
            make.width.equalTo(commentBtn)
        }
        
        let firstLineView  = addChildLineView()
        firstLineView.snp_makeConstraints { (make) in
            make.centerX.equalTo(retweetBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
        let SecondLineView = addChildLineView()

        SecondLineView.snp_makeConstraints { (make) in
            make.centerX.equalTo(commentBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        //竖线的约束
        firstLineView.snp_makeConstraints { (make) in
            
        }
        
        SecondLineView.snp_makeConstraints { (make) in
            
        }
    }
    
    
    
    
    
    
    
    
    //创建Button按钮的方法
    private func addChildButton(imageName: String,title: String)->(UIButton) {
        let button = UIButton()
        button.setImage(UIImage(named: imageName), for: .normal)
        
        button.setTitle(title, for: .normal)
        //字体大小
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        //字体颜色
        button.setTitleColor(UIColor.darkGray, for: .normal)
        //设置背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), for: .normal)
        
        //去掉高亮效果
        button.adjustsImageWhenHighlighted = false
        addSubview(button)
        
        return button
    }
    
    //创建竖线视图
    private func addChildLineView() -> UIImageView{
        let imageView  = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(imageView)
        
        return imageView
    }

}
